package com.etc.demo0530.service.impl;

import com.etc.demo0530.entity.Goods;
import com.etc.demo0530.mapper.GoodsMapper;
import com.etc.demo0530.service.GoodsServie;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Service
public class GoodsServiceImpl  implements GoodsServie {

    //需要使用GoodsMapper的代码执行crud

    @Autowired
    private GoodsMapper mapper;

    @Override
    public PageInfo<Goods> selectByLike(Integer pageNum, Integer pageSize, String keywords) {

        //分页插件PageHelper的startpage方法
        PageHelper.startPage(pageNum,pageSize);
        Page<Goods> pageList = mapper.selectByLike("%" + keywords + "%");

        //构造一个PageInfo对象
        PageInfo<Goods> pageInfo = new PageInfo<>(pageList);
        return pageInfo;
    }

    @Override
    public Goods selectById(Integer goodsid) {
        return mapper.selectById(goodsid);
    }

    @Override
    public Integer deleteById(Integer goodsid) {
        return mapper.deleteById(goodsid);
    }

    @Override
    public Integer addGoods(Goods goods) {
        //实际增加 还要判断 是否重复。。。。。
        return mapper.addGoods(goods);
    }
}
